package com.hh.workflow.action;

import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.hh.baseframework.exception.MessageException;
import com.hh.baseframework.util.dto.ExtCheckTree;
import com.hh.baseframework.util.http.Request;
import com.hh.baseframework.util.io.FileUtil;
import com.hh.system.inf.IImageAction;
import com.hh.system.util.base.BaseAction;
import com.hh.system.util.model.ReturnModel;
import com.hh.workflow.service.impl.TaskWfService;

@SuppressWarnings("serial")
public class ActionTask extends BaseAction implements IImageAction {
	@Autowired
	private TaskWfService taskService;
	private String piid;
	private String taskId;
	private String pdid;
	private String deploymentId;
	private String pdkey;
	private String activityId;
	private String node;
	private Map<String, String> userMap = new HashMap<String, String>();
	private Map<String, String> conditionMap = new HashMap<String, String>();
	private byte[] bytes = null;
	private String contentType = "image/png";
	private String actionType;

	public byte[] getBytes() {
		return bytes;
	}

	public void setBytes(byte[] bytes) {
		this.bytes = bytes;
	}

	public String getContentType() {
		return contentType;
	}

	public void setContentType(String contentType) {
		this.contentType = contentType;
	}

	public void queryTaskList() {
		this.returnResult(taskService.queryTaskList());
	}

	public void queryHiTaskListByPiid() {
		this.returnResult(taskService.queryHiTaskListByPiid(piid));
	}
	
	public void queryHiTaskListByAssignee() {
		this.returnResult(taskService.queryHiTaskListByAssignee(this.getPageRange()));
	}

	public void manager() {
		this.returnResult(taskService.manager(actionType,pdkey, activityId, taskId));
	}

	public void submit() {
		Map<String, Object> paraMap = Request.getParamMapByRequest(request);
		try {
			taskService.submit(paraMap, userMap, conditionMap);
		} catch (MessageException e) {
			this.getResultMap().put("returnModel",
					new ReturnModel(e.getMessage()));
		}
		this.returnResult();
	}

	public void saveComment() {
		Map<String, Object> paraMap = Request.getParamMapByRequest(request);
		taskService.saveComment(paraMap);
		this.returnResult();
	}

	public void queryCommentByPiidAndTaskId() {
		this.returnResult(taskService.queryCommentByPiidAndTaskId(piid, taskId));
	}

	public String showPic() {
		InputStream inputStream = null;
		inputStream = taskService.findPicByPdid(pdid);
		this.setBytes(FileUtil.stream2Byte(inputStream));
		return "image";
	}

	public void claim() {
		taskService.claim(taskId);
	}

	public void queryPicHiTask() {
		List<Map<String, Object>> result = taskService.queryPicHiTask(piid,
				pdid);
		this.returnResult(result);
	}

	public void queryStepByActivityId() {
		String actId = activityId;
		if (!"root".equals(node)) {
			actId = node;
		}
		List<ExtCheckTree> extCheckTrees = taskService.queryStepByActivityId(
				pdid, piid, actId);
		this.returnResult(extCheckTrees);
	}

	public void queryCommentByTaskId() {
		this.returnResult(taskService.queryCommentByTaskId(taskId));
	}

	public void queryHiAssigneesByActIdAndPiid() {
		this.returnResult(taskService.queryHiAssigneesByActIdAndPiid(piid,
				activityId));
	}

	public void addTaskUser() {
		taskService.addTaskUser(taskId, request.getParameter("userStrIds"));
		this.returnResult();
	}

	public String getActivityId() {
		return activityId;
	}

	public void setActivityId(String activityId) {
		this.activityId = activityId;
	}

	public String getPdkey() {
		return pdkey;
	}

	public void setPdkey(String pdkey) {
		this.pdkey = pdkey;
	}

	public String getPdid() {
		return pdid;
	}

	public void setPdid(String pdid) {
		this.pdid = pdid;
	}

	public String getPiid() {
		return piid;
	}

	public void setPiid(String piid) {
		this.piid = piid;
	}

	public String getTaskId() {
		return taskId;
	}

	public void setTaskId(String taskId) {
		this.taskId = taskId;
	}

	public String getNode() {
		return node;
	}

	public void setNode(String node) {
		this.node = node;
	}

	public Map<String, String> getUserMap() {
		return userMap;
	}

	public void setUserMap(Map<String, String> userMap) {
		this.userMap = userMap;
	}

	public Map<String, String> getConditionMap() {
		return conditionMap;
	}

	public void setConditionMap(Map<String, String> conditionMap) {
		this.conditionMap = conditionMap;
	}

	public String getDeploymentId() {
		return deploymentId;
	}

	public void setDeploymentId(String deploymentId) {
		this.deploymentId = deploymentId;
	}

	public String getActionType() {
		return actionType;
	}

	public void setActionType(String actionType) {
		this.actionType = actionType;
	}

}
